package net.jxtz.jxtzos.authentication;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 *
 * 继承实现了spring security的UserDetails
 *
 * @author a123
 */
@Data
@NoArgsConstructor
public class MyUserDetails implements UserDetails {

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long id;

    private String nikeName;

    private String userName;

    private String password;

    private String headUrl;

    private List<SimpleGrantedAuthority> authorities;

    public MyUserDetails(Long id,String userName, String password, List<SimpleGrantedAuthority> authorities){
        this.id = id;
        this.userName = userName;
        this.password = password;
        this.authorities = authorities;
    }

    public MyUserDetails(Long id,String userName, String password, List<SimpleGrantedAuthority> authorities, String nikeName, String headUrl){
        this.id = id;
        this.userName = userName;
        this.password = password;
        this.authorities = authorities;
        this.nikeName = nikeName;
        this.headUrl = headUrl;
    }


    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
